using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Net;
using System.Net.Mail;

namespace MVCWeb.Controllers
{
    public class CustomErrorController : Controller
    {
        //
        // GET: /CustomError/

        public ActionResult Unknown()
        {
            if (System.Configuration.ConfigurationManager.AppSettings["ErrorLogging"] == "email")
            {
                string error = string.Format("Error at: {0}", Request.Url);
                MailMessage message = new MailMessage();
                message.From = new MailAddress("ngothanhtung.it@gmail.com");
                message.CC.Add(new MailAddress("ngothanhtung.it@gmail.com"));
                message.To.Add(new MailAddress("johnngoit@gmail.com"));
                message.Subject = "Error on " + System.Configuration.ConfigurationManager.AppSettings["SiteName2"] + " Production at " + DateTime.Now.ToString();
                message.Body = error;
                message.IsBodyHtml = true;

                SmtpClient smtp = new SmtpClient();
                smtp.Send(message);

                //Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                ViewData["CurrentView"] = error;
            }
            return View();
        }

        public ActionResult LighthouseUnknown()
        {
            if (System.Configuration.ConfigurationManager.AppSettings["ErrorLogging"] == "email")
            {
                string error = string.Format("Error at: {0}", Request.Url);
                MailMessage message = new MailMessage();
                message.From = new MailAddress("ngothanhtung.it@gmail.com");
                message.CC.Add(new MailAddress("ngothanhtung.it@gmail.com"));
                message.To.Add(new MailAddress("johnngoit@gmail.com"));
                message.Subject = "Error on " + System.Configuration.ConfigurationManager.AppSettings["SiteName2"] + " Production at " + DateTime.Now.ToString();
                message.Body = error;
                message.IsBodyHtml = true;

                SmtpClient smtp = new SmtpClient();
                smtp.Send(message);

                //Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                ViewData["CurrentView"] = error;
            }
            return View();
        }
    }
}
